<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" v-if="sysMode==3||sysMode==4">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商家名称">
              <a-input placeholder="请输入商家名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="管理人">
              <a-input placeholder="请输入管理人" v-model="queryParam.custodianName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="联系电话">
              <a-input placeholder="请输入联系电话" v-model="queryParam.custodianPhone"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="店铺状态">
              <a-select :default-value="null" v-model="queryParam.status" @change="searchQuery">
                <a-select-option :value="null">
                  全部
                </a-select-option>
                <a-select-option :value="1">
                  正常
                </a-select-option>
                <a-select-option :value="0">
                  冻结
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="地区">
              <j-area-linkage v-model="queryParam.did" type="cascader"/>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="7" :md="8" :sm="24">
            <a-form-item label="创建时间">
              <a-range-picker format="YYYY-MM-DD" :placeholder="['开始时间', '结束时间']" @change="onDateChange"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="sysMode==3||sysMode==4">
      <a-button @click="handlePageAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table"
               size="middle"
               :scroll="{x:true}"
               bordered
               rowKey="id"
               :columns="columns"
               :dataSource="dataSource"
               :pagination="ipagination"
               :loading="loading"
               class="j-table-force-wrap"
               @change="handleTableChange">

        <template slot="statusSlot" slot-scope="text,record,index">
          <a-tag color="green" v-if="text==1">
            正常
          </a-tag>
          <a-tag color="red" v-else>
            冻结
          </a-tag>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handlePageEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handlePageDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-if="record.status==1&&shopType==1">
                <a @click="statusChange(0,record.id,'冻结')">冻结</a>
              </a-menu-item>
              <a-menu-item v-if="record.status==0&&shopType==1">
                <a @click="statusChange(1,record.id,'解冻')">解冻</a>
              </a-menu-item>
              <a-menu-item v-if="record.id!='A00001A00001'&&record.status==0&&!record.dealNum">
                <a-popconfirm title="删除店铺会清空所有相关数据，确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <sms-shop-modal ref="modalForm" @ok="modalFormOk"></sms-shop-modal>
  </a-card>
</template>

<script>
import {getAction, postAction, putAction} from '@/api/manage'
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import SmsShopModal from './modules/SmsShopModal'
import JDate from '@/components/jeecg/JDate.vue'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JAreaLinkage from '@/components/jeecg/JAreaLinkage'

export default {
  name: 'SmsShopList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    SmsShopModal, JDate, JDictSelectTag, JAreaLinkage
  },
  data() {
    return {
      description: 'sms_shop管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '商铺名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '商铺logo',
          align: "center",
          dataIndex: 'logoUrl',
          scopedSlots: {customRender: "imgSlot"}
        },

        {
          title: '管理人',
          align: "center",
          dataIndex: 'custodianName'
        },

        {
          title: '联系方式',
          align: "center",
          dataIndex: 'custodianPhone'
        },
        {
          title: '店铺地址',
          align: "center",
          dataIndex: 'address'
        },

        {
          title: '店铺销量',
          align: "center",
          sorter: true,
          dataIndex: 'dealNum',
          customRender: function (text) {
            return !text ? 0 : text;
          }
        },
        {
          title: '提现手续费比例',
          align: "center",
          sorter: true,
          dataIndex: 'cashRate',
          customRender: function (text) {
            return (!text ? 0 : text) + "%";
          }
        },
        {
          title: '入驻时间',
          align: "center",
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: 'statusSlot'}
        },
        // {
        //   title: '是否推荐  0 不推荐  1推荐(预留)',
        //   align: "center",
        //   dataIndex: 'isRecommend'
        // },

        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/mallBase/smsShop/list",
        editStatus: "/mallBase/smsShop/changeShopStatus",
        delete: "/mallBase/smsShop/delete",
        deleteBatch: "/mallBase/smsShop/deleteBatch",
        exportXlsUrl: "/mallBase/smsShop/exportXls",
        importExcelUrl: "mallBase/smsShop/importExcel",

      },
      dictOptions: {},
    }
  },
  created() {
    console.log(this.sysMode);
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handlePageAdd() {
      this.$router.push({path: '/shop/detail', query: {disabled: false}})
    },
    handlePageEdit(record) {
      this.$router.push({path: '/shop/detail', query: {id: record.id, disabled: false}})
    },
    handlePageDetail(record) {
      this.$router.push({path: '/shop/detail', query: {id: record.id, disabled: true}})
    },
    statusChange: function (status, id, str) {
      var that = this
      this.$confirm({
        title: "确认" + str,
        content: status == 1 ? "是否" + str + "店铺?" : "确定要冻结商家店铺吗，冻结后将在商城内隐藏该商家的所有商品，且商品无法下单。商家管理员仍可以登录后台进行订单相关处理，提现等操作。",
        onOk: function () {
          that.loading = true
          putAction(that.url.editStatus, {id: id, status: status}).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.loading = false
          })
        }
      })
    },
    initDictConfig() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
